<template>
  <div class="login-img">
    <div class="login-container">
      <h3 class="login-title">欢迎登录数字图书馆系统</h3>
      <el-form
          :model="loginUser"
          :rules="userValidRule"
          status-icon
          ref="loginForm"
          label-position="left"
          label-width="0px"
          class="demo-ruleForm login-page"
      >
        <el-form-item prop="username">
          <el-input
              type="text"
              v-model="loginUser.username"
              auto-complete="off"
              placeholder="用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
              type="password"
              v-model="loginUser.password"
              auto-complete="off"
              placeholder="密码"
          ></el-input>
        </el-form-item>
        <el-form-item style="width: 100%">
          <el-button
              type="primary"
              style="width: 100%"
              @click="handleLogin"
              :loading="login"
          >登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      login: false,
      loginUser: {},
      userValidRule: {
        account: [{required: true, message: "请输入账号", trigger: "blur"}],
        checkPass: [{required: true, message: "请输入密码", trigger: "blur"}],
      },
    };
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.login = true;
          sessionStorage.setItem("user", '{"name":"aa"}');
          this.$router.push({path: "/Home"});
          /*var loginParams = { username: this.loginUser.username, password: this.loginUser.password, identifycode: this.loginUser.identifycode };
          requestLogin(loginParams).then(data => {
            this.logining = false;
            let { msg, code, user } = data;
            if (code !== 200) {
              this.$message({
                message: msg,
                type: 'error'
              });
            } else {
              sessionStorage.setItem('user', JSON.stringify(user));
              this.$router.push({ path: '/BookManage' });
            }
          });*/
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.login-img {
  width: 100%;
  height: 100%;
  background-image: url("../assets/libraryback.jpeg");
  background-size: cover;
  background-position: center;
  position: fixed;
  top: 0;
  left: 0;
  min-width: 1000px;
  z-index: -10;
  zoom: 1;
  background-color: #fff;
  background-repeat: no-repeat;
  -webkit-background-size: cover;
  -o-background-size: cover;
}

.login-container {
  border: 1px solid #dcdfe6;
  width: 350px;
  margin: 20% auto;
  padding: 35px 35px 15px 35px;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  box-shadow: 0 0 25px #909399;
  background: white;
}

.login-title {
  text-align: center;
  margin: 0 auto 40px auto;
  color: #303133;
}
</style>
